package cn.ltgodm.template.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ltgodm
 * @date 2024-03-17 20:17:19
 * 排序枚举
 */
@Getter
@AllArgsConstructor
public enum SortEnum {
    SORT_ACC("升序", "acc"),
    SORT_DESC("降序", "desc");

    private final String text;

    private final String value;


    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static SortEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (SortEnum anEnum : SortEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
}
